Load libraries
library(ggmap)
library(dplyr)
library(gridExtra)
Load the data
coord.data.frame = read.csv("Snap_Coordinates.csv")
Prepare data
coord.data.frame = coord.data.frame %>%
filter(Source != "MINDCONNECT") %>%
rename(case = X, source = Source, lon = Longitude, lat = Latitude)
You can also embed plots, for example:
cases = unique(coord.data.frame$case)
plots = lapply(cases, function(x) {
current.data = coord.data.frame %>% filter(case == x)
map.center = (current.data %>% filter(source == "STREET") %>% select(lon, lat))[1,]
base.map = get_map(location = map.center, zoom = 17)
plot = ggmap(base.map) +
geom_point(data = current.data, aes(x = lon, y = lat, color = source, alpha = 0.8),
size = 3) +
ggtitle(x) +
theme(plot.margin = unit(c(2,0,0,0), "lines"), axis.title = element_blank(),
axis.line = element_blank(), axis.text = element_blank(),
axis.ticks = element_blank(), legend.position = "bottom",
legend.title = element_blank(), legend.text = element_text(size = 6)) +
guides( alpha = FALSE)
})
do.call(grid.arrange, c(plots, nrow = ceiling(length(plots) / 3), ncol = 3, top = title))